/** 
  课程成绩管理空白登分表
*/
<template>
  <div class="blank-score-sheet-container">
    <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
      <div class="title">
        <div class="float-left">
          {{ $t('scoreEntryMana.blankScoreSheet') }}
        </div>
        <div class="float-right">
          <el-button @click="exportBlankSheet()">{{ $t('scoreMangementBase.export') }}</el-button>
        </div>
      </div>
      <div class="blank-score-sheet">
        <div class="blank-title">{{ $t('scoreEntryMana.tjCollege') }}{{ basicInfo.calendarYearTermCn }}{{ $t('scoreEntryMana.scoreRegistForm') }}</div>
        <el-row class="blank-sub-title">
          <!-- 课程名称 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.courseName') }}：{{ basicInfo.courseName }}
          </el-col>
          <!-- 课程代码 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.courseCode') }}：{{ basicInfo.courseCode }}
          </el-col>
          <!-- 课程序号 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.courseNum') }}：{{ basicInfo.courseNo }}
          </el-col>
        </el-row>
        <el-row class="blank-sub-title">
          <!-- 开课学院 -->
          <el-col :span="8">
            {{ $t('scoreEntrySwitch.startCollege') }}：{{ basicInfo.facultyI18n }}
          </el-col>
          <!-- 教师 -->
          <el-col :span="8">
            {{ $t('scoreEntryMana.tearcher') }}：{{ basicInfo.teacherCode }}{{ basicInfo.teacherName }}
          </el-col>
          <!-- 班级人数 -->
          <el-col :span="8">
            <!-- 课程成绩管理 -->
            <span v-if="detailInfo.examType === '2'">
              {{ $t('scoreEntryMana.classSize') }}：{{ basicInfo.selectNum || 0 }}
            </span>
            <!-- 重缓考成绩管理 -->
            <span v-if="detailInfo.examType === '1'">
              {{ $t('scoreEntryMana.redelaySize') }}：{{ basicInfo.selectNum || 0 }}
            </span>
          </el-col>
        </el-row>
        <el-row class="blank-sub-title">
          <!-- 成绩类型 -->
          <el-col :span="24">
            {{ $t('scoreEntryMana.gradeType') }}：
            <!-- 期末总评 -->
            <span v-if="detailInfo.examType === '2'">
              {{ scoreStructure }}
            </span>
            <!-- 重缓考 -->
            <span v-if="detailInfo.examType === '1'">
              {{ $t('redelayTestScoreMana.redelayScore') }}
            </span>
          </el-col>
        </el-row>
        <el-row style="margin: 15px 0;">
          <el-col :span="12">
            <el-table border :data="dataListLeft" size="mini">
              <!-- 序号 -->
              <el-table-column :label="$t('scoreEntryMana.serialNumber')" type="index" align="center" width="80"></el-table-column>
              <!-- 学号 -->
              <edu-table-column :label="$t('scoreMangementBase.studentId')" prop="studentId" align="center"></edu-table-column>
              <!-- 姓名 -->
              <edu-table-column :label="$t('scoreMangementBase.studentName')" prop="studentName" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.resetFlag === 'Y'" style="color: red;">*</span>{{ scope.row.studentName }}
                </template>
              </edu-table-column>
              <!-- 期末总评 -->
              <template v-if="detailInfo.examType === '2'">
                <!-- 总评成绩成分 -->
                <template v-for="item in options.scoreType">
                  <edu-table-column :key="item.key" :label="item.label" prop="" align="center"></edu-table-column>
                </template>
                <!-- 总评成绩 -->
                <edu-table-column :label="$t('scoreEntryMana.overallRating')" prop="" align="center"></edu-table-column>
              </template>
              <!-- 重缓考 -->
              <template v-if="detailInfo.examType === '1'">
                <!-- 重考成绩 -->
                <edu-table-column :label="$t('redelayTestScoreMana.retakeScore')" prop="" align="center"></edu-table-column>
                <!-- 缓考成绩 -->
                <edu-table-column :label="$t('redelayTestScoreMana.postponement')" prop="" align="center"></edu-table-column>
              </template>
            </el-table>
          </el-col>
          <el-col :span="12">
            <el-table border :data="dataListRight" size="mini">
              <!-- 序号 -->
              <el-table-column :label="$t('scoreEntryMana.serialNumber')" type="index" align="center" width="80">
                <template slot-scope="scope">
                  {{ scope.$index + 1 + dataListLeft.length}}
                </template>
              </el-table-column>
              <!-- 学号 -->
              <edu-table-column :label="$t('scoreMangementBase.studentId')" prop="studentId" align="center"></edu-table-column>
              <!-- 姓名 -->
              <edu-table-column :label="$t('scoreMangementBase.studentName')" prop="studentName" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.resetFlag === 'Y'" style="color: red;">*</span>{{ scope.row.studentName }}
                </template>
              </edu-table-column>
              <!-- 期末总评 -->
              <template v-if="detailInfo.examType === '2'">
                <!-- 总评成绩成分 -->
                <template v-for="item in options.scoreType">
                  <edu-table-column :key="item.key" :label="item.label" prop="" align="center"></edu-table-column>
                </template>
                <!-- 总评成绩 -->
                <edu-table-column :label="$t('scoreEntryMana.overallRating')" prop="" align="center"></edu-table-column>
              </template>
              <!-- 重缓考 -->
              <template v-if="detailInfo.examType === '1'">
                <!-- 重考成绩 -->
                <edu-table-column :label="$t('redelayTestScoreMana.retakeScore')" prop="" align="center"></edu-table-column>
                <!-- 缓考成绩 -->
                <edu-table-column :label="$t('redelayTestScoreMana.postponement')" prop="" align="center"></edu-table-column>
              </template>
            </el-table>
          </el-col>
        </el-row>
        <el-row class="blank-sub-title">
          <el-col :span="24">
            <div>{{ $t('scoreEntryMana.explain') }}：<span style="color: red;">*</span> {{ $t('scoreEntryMana.explainTip') }}</div>
          </el-col>
        </el-row>
        <el-row class="blank-sub-title" style="margin-top: 25px;">
          <el-col :span="6">
            {{ $t('scoreEntryMana.tearcherSign') }}：
          </el-col>
          <el-col :span="6">
            {{ $t('scoreEntryMana.entryPersonSign') }}：
          </el-col>
          <el-col :span="6">
            {{ $t('scoreEntryMana.entryTime') }}：<span style="margin-left: 15px;">{{ $t('scoreEntryMana.year') }}</span><span style="margin-left: 15px;">{{ $t('scoreEntryMana.month') }}</span><span style="margin-left: 15px;">{{ $t('scoreEntryMana.date') }}</span>
          </el-col>
          <el-col :span="6">
            {{ $t('scoreEntryMana.collegeStamp') }}：
          </el-col>
        </el-row>
      </div>
    </el-card>
    <edu-export-dialog
      :disabled="exportButton"
      :title="$t('message.prompt')"
      ref="downloadRef"
      :data="exportResult">
    </edu-export-dialog>
  </div>
</template>
<script>
import baseUrl from 'common/src/api/scoreManagement/env';
import scoreManagementApi from 'common/src/api/scoreManagement/scoreManagement';
import UTILS from "common/src/utils/utils";
import { queryDic } from "common/src/api/dictionary";
export default {
  components: {

  },
  data () {
    return {
      basicInfo: {},
      dataListLeft: [],
      dataListRight: [],
      options: {
        scoreType: []
      },
      scoreStructure: '',
      exportButton: false,
      exportResult: null
    }
  },
  props: {
    detailInfo: {
      type: Object,
      default: () => {}
    }
  },
  created() {

  },
  mounted() {
    this.initOptions()
    scoreManagementApi.getMinorGradeInfos(this.detailInfo).then(res => {
      if (res.code === 200) {
        this.basicInfo = res.data
        let leftTableLength = Math.ceil(this.basicInfo.studentList.length / 2) // 向上取整
        this.dataListLeft = this.basicInfo.studentList.splice(0, leftTableLength)
        this.dataListRight = this.basicInfo.studentList
      }
    })
  },
  methods: {
    initOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: [
          "X_ZPCJCF_FX" // 辅修总评成绩成分
        ]
      }
      queryDic(data).then(res => {
        let currentObj = res.data.X_ZPCJCF_FX
        for (let key in currentObj) {
          // 课程成绩管理--总评
          if (this.detailInfo.examType === '2') {
            if (key === '11005' || key === '11006' || key === '11007' || key === '11008') {
              this.scoreStructure += currentObj[key] + '（__%）'
              this.options.scoreType.push({
                key: key,
                value: key,
                label: currentObj[key]
              })
            }
          }
          // 重缓考成绩管理--重缓考
          if (this.detailInfo.examType === '1') {
            if (key === '11003' || key === '11004') {
              this.scoreStructure += currentObj[key] + '（__%）'
              this.options.scoreType.push({
                key: key,
                value: key,
                label: currentObj[key]
              })
            }
          }
        }
      })
    },
    // 返回主页
    backToMain() {
      this.$emit('refresh-main-page')
    },
    // 导出
    exportBlankSheet() {
      this.exportResult = null
      this.$refs.downloadRef.open()
      this.exportButton = true
      window.location.href = `${baseUrl}/minorCourseGradeManageController/exportMinorGradeBlankTable?calendarId=` + this.basicInfo.calendarId + '&teachingClassId=' + this.basicInfo.teachingClassId + '&campus=' + this.detailInfo.campus + '&examType=' + this.detailInfo.examType + '&language=' + this.$store.getters.language
      setTimeout(() => {
        this.$refs.downloadRef.close()
        this.exportButton = false
      }, 3000)
    }
  },
  watch: {
  }
}
</script>

<style lang="scss" scoped>
  .blank-score-sheet-container ::v-deep {
    .title {
      margin-bottom: 40px;
      font-size: 18px;
    }
    .blank-title {
      margin-bottom: 40px;
      text-align: center;
      font-size: 18px;
    }
    .blank-sub-title {
      padding: 8px 0;
      font-size: 12px;
    }
  }
</style>